package server_logic;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import server_gui.ServerLog;
import server_gui.ServerGui;

public class CcrmServer 
{
	 
	public static DBconnector con;
	private static inetCon inet;
	private static ServerGui servgui;

  /**
   * main method starts our gui 
   * @param args
   */
  
  public static void main(String[] args) 
  {
    
    servgui= new ServerGui();
    servgui.setVisible(true);
    
    servgui.connect.addActionListener(new ActionListener() {
    	
		public void actionPerformed(ActionEvent arg0) {
			//if(!con.isConnected())
		    con = new DBconnector(servgui.getSchema(),servgui.getDbUser(),servgui.getDbPass());
		    
			if(con.isConnected()){
				servgui.connect.setBackground(Color.GREEN);
				servgui.connect.setText("connected!!");
				servgui.connect.setEnabled(false);
				servgui.setContentPane((new ServerLog()).getContentPane());
				servgui.setTitle("Server Logs");
				inet = new inetCon(servgui.getPort());
		    	try{
		    		inet.listen();
		    	}catch(Exception ex){
		    		System.out.println("ERROR - Could not listen for clients!");
		    	}
			}
			
			
			
			
		}
	});
    

  }//main
}// CcrmServer

